package com.liuxn.dubbo.sample.demo.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Knife4j（Swagger2）的配置
 */
@Configuration
@EnableSwagger2
public class Knife4jConfiguration {

    /**
     * 模拟请求ip
     */
    private String host = "http://java.qingtian.cn";


    @Autowired
    private OpenApiExtensionResolver openApiExtensionResolver;


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("在线api文档")
                .description("xxx系统接口文档")
                //服务条款URL
                .termsOfServiceUrl("http://xxx.sss")
                //联系人信息
                .contact(new Contact("xxx", "http://www.xxx.com", "xx@xx.com"))
                //版本号
                .version("1.0.0")
                .build();
    }


    @Bean
    public Docket docket() {
        String groupName = "01用户中心V1";
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .host(host)
                .apiInfo(apiInfo())
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.liuxn.dubbo.sample.demo.controller"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions(groupName));
        return docket;
    }


}
